package key;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Delete
 */
@WebServlet("/Delete")
public class Delete extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	Database db = new Database();
	Log log = new Log();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Delete() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String uidS = (String) request.getSession().getAttribute("uid");
		String[] toDel = request.getParameterValues("adt");
		String uname = (String) request.getSession().getAttribute("uname");
		
		int uid = Integer.parseInt (uidS);
		db.delete(toDel, uid);
		
		List<Info> timeList = db.createList(uname, uidS);
		request.setAttribute("uid", uidS);
		request.setAttribute("timeList", timeList);//返回结果集
		request.setAttribute("uname", uname);
		request.getRequestDispatcher("inf.jsp").forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
